

/**
 * Class to compute the number of days between two dates  ROB WAS HERE
 *
 */
public class DateCalculator {

	/**
	 * Constructor that takes two strings as input
	 * 
	 * InvalidDateString is thrown if the strings are not in the format of DD/MM/YYYY
	 * @param one
	 * @param two
	 * @throws Date.InvalidDateString
	 * @throws CalculationError 
	 */
	public DateCalculator(String one, String two) throws InvalidDateString, CalculationError {
		String[] strings = new String[2];
		strings[0] = one;
		strings[1] = two;
		calculate(strings);
	}
	
	
	/**
	 * Constructor that takes an array of strings as inputs
	 * 
	 * @param args
	 * @throws InvalidDateString 
	 * @throws Date.CalculationError 
	 */
	public DateCalculator(String[] args) throws InvalidDateString, CalculationError {
		calculate(args);
	}
	
	/**
	 * Calculates the number of days between two dates inputed as an array of strings
	 * 
	 * Constructs two date objects and calculates the number of days between the two dates.
	 * 
	 * @param args
	 * @throws Date.InvalidDateString
	 * @throws Date.CalculationError
	 */
	private void calculate(String[] args) throws InvalidDateString, CalculationError {
		if (args.length != 2) {
			System.err.println("Requires 2 strings in the format of MM/DD/YYYY");
			throw new InvalidDateString("Requires 2 strings in the format of MM/DD/YYYY");
		}

		Date date1 = new Date(args[0]);
		Date date2 = new Date(args[1]);
		try {
			
			int numberOfDays = date1.calculateNumberOfDaysBetween(date2);
			System.out.println("There are " + numberOfDays + " between " + date1 + " and " + date2);
		} catch (CalculationError e) {
			int numberOfDays = date2.calculateNumberOfDaysBetween(date1);
			System.out.println("There are " + numberOfDays + " between " + date2 + " and " + date1);
		}
	}
	
	
	
	/**
	 * Application to compute the number of days between 2 valid dates between 1/1/1800 and 1/2/2100
	 * 
	 * The dates are inputed as two strings in the format of MM/DD/YYYY
	 * 
	 * For example "15/3/2004" "31/3/2004"
	 * 
	 * If any other than 2 strings are provided as command line input several test cases are executed
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		
		try {
			new DateCalculator(args);
			return;
		} catch (InvalidDateString e) {
			e.printStackTrace();
		} catch (CalculationError e) {
			e.printStackTrace();
		}
	}

}